<template>
	<view class="activityBox">
		<view class="title">
			活动
		</view>
		<!-- 搜索 -->
		<view class="searchBox" @click="tiaosou">
			<view class="inputBox">
				<image src="/static/pages/index/searchImg.png" mode="" class="searchImg"></image>
				<input disabled="true" class="inpt" placeholder="请输入活动名称"
					placeholder-style="color:#9DA0A9;font-size:26rpx;" />
			</view>
			<view class="searchInput">
				搜索
			</view>
		</view>
		<!-- 日期筛选 -->
		<view class="dateContent">
			<view class="uni-list">
				<view class="uni-list-cell">
					<view class="uni-list-cell-db">
						<picker mode="date" @change="bindDateChange" start="2022-01" end="2042-01" fields="month">						
						    <view class="uni-input">可选择：{{date}}</view>
						</picker>
					</view>
				</view>
			</view>
			
			<view class="flex-text">
					<text>项目数量： {{shuju.count}}</text>
					<text>已申请场次： {{shuju.number}}</text>
			</view>
			
		</view>
		<!-- 内容 -->
		<view class="activityContent">
			<view class="activityList" v-for="(item,index) in contentList" @click="hd_detail(item.id)">
				<view class="ctime">
					<text class="ctimew">活动时间:</text>
					<text style="margin-left: 20rpx;">{{item.starttime_text}}--{{item.endtime_text}}</text>
				</view>
				<view class="wire">
					
				</view>
				<view class="acName">
					{{item.name}}
				</view>
				<!-- <view class="fundsNum">
					<view class="fundsNum1">
						预算：
					</view>
					<view class="fundsNum2">
						{{item.money}}
					</view>
				</view> -->
				<view class="quota">
					<view class="quota1">
						剩余场次:
					</view>
					<view class="quota2">
						{{item.remaining}}
					</view>
				</view>
			</view>
		</view>
		<dibudao indexs='2'></dibudao>
	</view>
</template>

<script>
	import {regionActivity} from '@/request/api.js';
	export default {
		data() {
			return {
				contentList: [],
				page:1,
				page2:1,
				pageShow:false,
				date: '点击选择',
				shuju:''  
			};
		},
		onShow() {
			this.page=1;
			this.pageShow=false;
			this.contentList=[]
			this.init()
		},
		onReachBottom() {
			if(this.pageShow){
				this.init()
			}
			if(this.data){
				this.fliter()
			}
		},
		methods:{
			init(){
				let _this = this;
				let data = {
					cate_id:0,
					page:_this.page,
					time:''
				}
				regionActivity(data).then(res=>{
					if(res.code==1){
						this.shuju =  res.data
						if(res.data.activity.data.length>0){
							_this.pageShow=true;
							_this.contentList = _this.contentList.concat(res.data.activity.data)
							_this.page++
							res.data.activity.data.forEach(item=>{
								console.log(item,'时间时间')
								console.log(item.starttime_text)
								if(item){
								item.starttime_text=item.starttime_text.slice(0,10)
								item.endtime_text=item.endtime_text.slice(0,10)
								}
							})
						}else{
							_this.pageShow=false
						}
						
					
					}
				}).catch(err=>{
					
				})
			},
			hd_detail:function(id){
				uni.navigateTo({
					url:`active_detail?id=${id}`
				})
				
			},
			bindDateChange: function(e) {
				this.date = e.target.value
				this.contentList = []
				console.log(this.date);
				// 按月筛选
				this.fliter(this.date)					
			},
			// 筛选函数
			fliter(date){
				this.page2 = 1
				let _this = this;
				let data = {
					cate_id:0,
					page:_this.page2,
					time: date
				}
				regionActivity(data).then(res=>{
					if(res.code==1){
						this.shuju = res.data
						if(res.data.activity.data.length>0){
							_this.pageShow=true;
							_this.contentList = _this.contentList.concat(res.data.activity.data)
							_this.page2++
							res.data.activity.data.forEach(item=>{
								console.log(item,'时间时间')
								console.log(item.starttime_text)
								if(item){
								item.starttime_text=item.starttime_text.slice(0,10)
								item.endtime_text=item.endtime_text.slice(0,10)
								}
							})
						}else{
							_this.pageShow=false
						}
					}
				}).catch(err=>{
					
				})
			},
			
			tiaosou:function(){
				uni.navigateTo({
					url:'/pages/groundPole/activityGround/activitySearch'
				})
			},
			
			formatDate: function(value) {
				let date = new Date(value * 1000);
				//时间戳为10位需*1000，时间戳为13位的话不需乘1000
				let y = date.getFullYear();
				let MM = date.getMonth() + 1;
				MM = MM < 10 ? ('0' + MM) : MM; //月补0
				let d = date.getDate();
				d = d < 10 ? ('0' + d) : d; //天补0
				let h = date.getHours();
				h = h < 10 ? ('0' + h) : h; //小时补0
				let m = date.getMinutes();
				m = m < 10 ? ('0' + m) : m; //分钟补0
				let s = date.getSeconds();
				s = s < 10 ? ('0' + s) : s; //秒补0
				console.log(y + '-' + MM + '-' + d);
				return y + '-' + MM + '-' + d; //年月日	
			},
		}
	}
</script>

<style lang="scss">
	
	.flex-text{
		color: #000;
		font-size: 32rpx;
		margin: 15rpx 0;
	}
	.flex-text>text{
		margin-right: 50rpx;
	}
	.dateContent{
		width: 90%;
		margin:  20rpx auto 10rpx;
	}
	.title{
		height: 88rpx;
		line-height: 88rpx;
		text-align: center;
		width: 100%;
		position: fixed;
		top: 0;
		z-index: 999;
		background: #fff;
		margin-top: var(--status-bar-height);
	}
	page {
		background-color: #FFFFFF;
	}

	.activityBox {
		width: 100%;
		box-sizing: border-box;
		padding-bottom: 40rpx;
		.searchBox {
			width: 100%;
			display: flex;
			justify-content: space-around;
			margin-top: 155rpx;

			.inputBox {
				width: 580rpx;
				height: 70rpx;
				background-color: #F0F1F5;
				border-radius: 60rpx;
				display: flex;

				.searchImg {
					width: 28rpx;
					height: 28rpx;
					margin: 21rpx 21rpx 0 24rpx;
				}
				
				.inpt {
					margin-top: 15rpx;
				}
			}

			.searchInput {
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #2E2F33;
				margin-right: 40rpx;
				margin-top: 17rpx;
			}
		}
		.activityContent{
			width: 100%;
			overflow: hidden;
			padding-bottom: 160rpx;
			.activityList{
				width: 670rpx;
				// height: 330rpx;
				margin: 40rpx auto 0;
				padding: 0 0 30rpx;
				box-shadow: 0rpx 0rpx 14rpx 0rpx rgba(211, 213, 220, 0.4);
				border-radius: 24px;
				.ctime{
					color: #979BA6;
					font-size: 26rpx;
					margin-left: 22rpx;
					height: 70rpx;
					line-height: 70rpx;
				}
				.wire{
					background-color: #ebecee;
					width: 100%;
					height: 4rpx;
					
					// margin-top: 23rpx;
				}
				.acName{
					font-size: 36rpx;
					line-height: 36rpx;
					color: #313233;
					margin-top: 30rpx;
					margin-left: 22rpx;
				}
				.fundsNum{
					display: flex;
					margin-top: 50rpx;
					margin-left: 22rpx;
					line-height: 36rpx;
					.fundsNum1{
						color: #313233;
						font-size: 36rpx;
						min-width: 220rpx;
					}
					.fundsNum2{
						color: #313233;
						font-size: 36rpx;
						// margin-left: 123rpx;
					}
				}
				.quota{
					display: flex;
					margin-top: 49rpx;
					margin-left: 22rpx;
					line-height: 36rpx;
					.quota1{
						color: #313233;
						font-size: 36rpx;
						min-width: 220rpx;
					}
					.quota2{
						color: #313233;
						font-size: 36rpx;
						// margin-left: 145rpx;
					}
				}
			}
		}
	}
</style>
